<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('团购ID')">
              <a-input :placeholder="$t('请输入团购ID')" v-model="queryParam.dealId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item :label="$t('商品名称')">
              <a-input :placeholder="$t('请输入商品名称')" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" icon="download" :loading="exloading" @click="handleExportXls($t('抖音套餐'))" style="margin-left: 8px" v-has="'BisTiktokGoodsController:export'">
                {{$t('导出')}}
              </a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px" v-has="'BisTiktokGoodsController:add'">{{$t('新增')}}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无图片')}}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{$t('无文件')}}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{$t('下载')}}
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'BisTiktokGoodsController:edit'">{{$t('修改')}}</a>
          <a-divider type="vertical" v-has="'BisTiktokGoodsController:edit'" />
          <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
            <a v-has="'BisTiktokGoodsController:delete'">{{$t('删除')}}</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <tiktok-goods-modal ref="modalForm" @ok="modalFormOk"></tiktok-goods-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TiktokGoodsModal from './modules/TiktokGoodsModal'
import { deleteAction, getAction, downFile, getFileAccessHttpUrl } from '@/api/manage'

export default {
  name: 'MeiTuanPackageSetting',
  mixins: [JeecgListMixin,mixinDevice],
  components: {
    TiktokGoodsModal,
  },
  data() {
    return {
      description: '抖音套餐管理页面',
      // 表头
      columns: [
        {
          title: this.$t('团购ID'),
          align: 'center',
          dataIndex: 'dealId',
        },
        {
          title: this.$t('商品名称'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('商品明细'),
          align: 'center',
          dataIndex: 'bisTiktokGoodsPackageList',
          customRender: (text, record, index) => {
            let title = ''
            text.forEach((ele) => {
              title = title + ele.goodsId_dictText + '*' + ele.amount + ' '
            })
            const answer = title.split(' ')
            return answer.map((item) => {
              return (<li>{item}</li>)
            })
          },
        },
        {
          title: this.$t('操作'),
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/tiktok/bisTiktokGoods/list',
        delete: '/tiktok/bisTiktokGoods/delete',
        exportXlsUrl: '/tiktok/bisTiktokGoods/exportXls',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: {
        dealId: '',
        name: '',
      },
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>